<template>
  <el-container class="layout-container">
    <el-main>
      <router-view></router-view>
    </el-main>
    
    <el-footer height="80px" class="footer">
      <div class="footer-content">
        <p>© 2025 心理健康测评系统 版权所有</p>
        <p>
          <el-link type="primary" href="/about">关于我们</el-link>
          <el-divider direction="vertical" />
          <el-link type="primary" href="/contact">联系我们</el-link>
          <el-divider direction="vertical" />
          <el-link type="primary" href="/privacy">隐私政策</el-link>
        </p>
      </div>
    </el-footer>
  </el-container>
</template>

<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import Cookies from 'js-cookie'

const router = useRouter()

const userInfo = computed(() => {
  const info = Cookies.get('userInfo')
  return info ? JSON.parse(info) : null
})

const isAdmin = computed(() => userInfo.value?.role === 'ADMIN')
const isExpert = computed(() => userInfo.value?.role === 'EXPERT')

const handleCommand = (command) => {
  switch (command) {
    case 'admin':
    case 'expert':
      router.push('/admin')  // 统一跳转到后台
      break
    case 'logout':
      Cookies.remove('token')
      Cookies.remove('userInfo')
      ElMessage.success('退出成功')
      router.push('/login')
      break
  }
}
</script>

<style scoped>
.layout-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.el-main {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding: 20px;
}

.footer {
  background-color: #f5f7fa;
  padding: 20px 0;
  margin-top: auto;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
  color: #666;
}

.footer-content p {
  margin: 5px 0;
}

@media (max-width: 768px) {
  .el-main {
    padding: 15px;
  }
}
</style> 